﻿using OestsCommon.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;

namespace OestsDataBase
{
    public static class PaperDAL
    {
        public static List<Paper> GetDataByTecher(int teacherid)
        {
            List<Paper> list = new List<Paper>();

            string strSql = "select * from T_Paper where teacher_id=" + teacherid;
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0) { return null; }
            foreach (DataRow dr in dt.Rows)
            {
                Paper paper = ReadData(dr);
                list.Add(paper);
            }

            return list;
        }
        public static List<Paper> GetData()
        {
            List<Paper> list = new List<Paper>();

            string strSql = "select * from T_Paper";
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0) { return null; }
            foreach (DataRow dr in dt.Rows)
            {
                Paper paper = ReadData(dr);
                list.Add(paper);
            }

            return list;
        }
        public static List<Paper> GetTheoryPapers(CombType combType)
        {
            List<Paper> list = new List<Paper>();

            string strSql = string.Format("select * from T_Paper where paper_type = 'Theory' and comb_type = '{0}'", combType.ToString());
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0) { return null; }
            foreach (DataRow dr in dt.Rows)
            {
                Paper paper = ReadData(dr);
                list.Add(paper);
            }

            return list;
        }
        /// <summary>
        /// 根据组卷类型获取操作试卷中的固定卷
        /// </summary>
        /// <param name="combType"></param>
        /// <returns></returns>
        public static List<Paper> GetOperatePapers(CombType combType)
        {
            List<Paper> list = new List<Paper>();

            string strSql = string.Format("select * from T_Paper where paper_type = 'Operate' and comb_type ='{0}'", combType.ToString());
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0) { return null; }
            foreach (DataRow dr in dt.Rows)
            {
                Paper paper = ReadData(dr);
                list.Add(paper);
            }

            return list;
        }


        private static Paper ReadData(DataRow dr)
        {
            Paper paper = new Paper();
            paper.Id = Int32.Parse(dr["paper_id"].ToString());
            paper.Name = dr["paper_name"].ToString();
            paper.PaperType = (PaperType)Enum.Parse(typeof(PaperType), dr["paper_type"].ToString());
            paper.ProjectId = Int32.Parse(dr["projectId"].ToString());
            paper.CombType = (CombType)Enum.Parse(typeof(CombType), dr["comb_type"].ToString());
            paper.TeacherId = Int32.Parse(dr["teacher_id"].ToString());
            if (!DBNull.Value.Equals(dr["use_count"]))
                paper.UseCount = (int)dr["use_count"];

            if (!DBNull.Value.Equals(dr["create_time"]))
                paper.CreateTime = (DateTime)dr["create_time"];
            return paper;
        }


        #region 添加一张试卷
        /// <summary>
        /// 添加一张试卷
        /// </summary>
        /// <param name="name">试卷名称</param>
        /// <param name="time">试卷时间</param>
        /// <param name="teacherId">教师id</param>
        /// <returns></returns>
        public static int AddPaper(Paper paper, int teacherid)
        {
            //  DBManager.Checkident("T_PaperOperates");
            if (paper.Name == "") return -1;
            string strSql = string.Format(@"insert into T_Paper (paper_name,paper_type,projectId,comb_type,teacher_id,create_time)values('{0}','{1}',{2},'{3}',{4},'{5}');SELECT @@Identity",
                paper.Name, paper.PaperType.ToString(), paper.ProjectId, paper.CombType.ToString(), teacherid, paper.CreateTime);
            object obj = SqlHelper.ExecuteScalar(strSql);

            int nID = Int32.Parse(obj.ToString());
            paper.Id = nID;
            if (paper.PaperType == PaperType.Theory)
                CreatTheoryPaperTable(paper);
            else //创建一张操作试卷表
                CreatPaperTable(paper);
            return nID;
        }

        public static int GetProjectIDByID(int paperId)
        {
            string strSql = "select * from T_Paper where paper_id=" + paperId;
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0) { return 0; }
            return int.Parse(dt.Rows[0]["projectId"].ToString());
        }

        public static Paper GetPaperByID(int paperId)
        {
            string strSql = "select * from T_Paper where paper_id=" + paperId;
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0) { return null; }

            Paper paper = ReadData(dt.Rows[0]);
            return paper;
        }
        /// <summary>
        /// 根据项目ID和试卷类型获取试卷列表
        /// </summary>
        /// <param name="projectID"></param>
        /// <param name="paperType"></param>
        /// <returns></returns>
        public static List<Paper> GetPapers(int projectID, PaperType paperType)
        {
            string strSql = string.Format("select * from T_Paper where projectId={0} and paper_type ='{1}'", projectID, paperType.ToString());
            List<Paper> papers = new List<Paper>();
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null || dt.Rows.Count == 0) { return null; }
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                papers.Add(ReadData(dt.Rows[0]));
            }
            return papers;
        }

        /// <summary>
        /// 创建对应操作试卷表
        /// </summary>
        /// <param name="id"></param>
        private static void CreatPaperTable(Paper paper)
        {
            string sqlCheck = string.Format("if object_id('{0}') is not null select 1 else select 0", "T_PaperOperate_" + paper.Id);
            if ((int)SqlHelper.ExecuteScalar(sqlCheck) == 0)
            {
                string sqlCreate = "";
                if (paper.CombType == CombType.Fixed)
                    sqlCreate = @"CREATE TABLE T_PaperOperate_" + paper.Id + @" (task_id bigint  primary key,post_id int , score nvarchar(MAX))";
                else
                    sqlCreate = @"CREATE TABLE T_PaperOperate_" + paper.Id + @" (task_count bigint , score int)";

                SqlHelper.ExecuteNonQuery(sqlCreate);
            }
            else
            {
                //清空已有数据，并且将自增自段恢复从1开始计数 
                string sql = "truncate table T_PaperOperate_" + paper.Id;
                SqlHelper.ExecuteNonQuery(sql);
            }
        }

        /// <summary>
        /// 创建对应理论试卷表
        /// </summary>
        /// <param name="id"></param>
        private static void CreatTheoryPaperTable(Paper paper)
        {
            string sqlCheck = string.Format("if object_id('{0}') is not null select 1 else select 0", "T_PaperTheory_" + paper.Id);
            if ((int)SqlHelper.ExecuteScalar(sqlCheck) == 0)
            {
                string sqlCreate = "";
                if (paper.CombType == CombType.Fixed)
                    sqlCreate = @"CREATE TABLE T_PaperTheory_" + paper.Id + @" (subject_id bigint , subject_score int,primary key(subject_id))";
                else
                    sqlCreate = @"CREATE TABLE T_PaperTheory_" + paper.Id + @" (single_count bigint , single_score int,mult_count bigint , mult_score int,tf_count bigint,tf_score int,tbId int)";

                SqlHelper.ExecuteNonQuery(sqlCreate);
            }
            else
            {
                //清空已有数据，并且将自增自段恢复从1开始计数 
                string sql = "truncate table T_PaperTheory_" + paper.Id;
                SqlHelper.ExecuteNonQuery(sql);
            }
        }
        #endregion

        public static bool ModifyPaper(Paper paper)
        {
            string strSql = string.Format("update T_Paper set paper_name='{0}',projectId={1} where paper_id = @paper_id", paper.Name, paper.ProjectId);
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@paper_id", paper.Id));
            if (n != 0)
            {
                return true;
            }
            return false;
        }

        /// <summary>
        /// 删除教师时，删除教师创建的考试
        /// </summary>
        /// <param name="teacherId"></param>
        /// <returns></returns>
        public static bool DelTeachInfo(int teacherId)
        {
            //获取教师管理的所有试卷ID
            string strSql = string.Format("select id from  T_Exam  where teacher_id = @id");
            DataTable dt = SqlHelper.ExecuteDataTable(strSql, new SqlParameter("@id", teacherId));
            if (dt == null || dt.Rows.Count == 0)
            {
                return true;
            }

            List<int> listPaperId = new List<int>();

            foreach (DataRow dr in dt.Rows)
            {
                listPaperId.Add(Int32.Parse(dr["id"].ToString()));
            }
            listPaperId.ForEach(n => DelPaper(n));
            return true;
        }


        public static int UpdatePaperUseCount(int paperId)
        {
            string strSql = string.Format("select use_count from  T_Paper  where paper_id = @paper_id");
            int count = 0;
            var obj = SqlHelper.ExecuteScalar(strSql, new SqlParameter("@paper_id", paperId));//原有的数据
            if (!DBNull.Value.Equals(obj))
            {
                count = (int)obj;
            }
            string strSql2 = string.Format("update T_Paper set use_count={0} where paper_id = @paper_id", count + 1);
            SqlHelper.ExecuteNonQuery(strSql2, new SqlParameter("@paper_id", paperId));
            return count + 1;

        }

        /// <summary>
        /// 删除试卷  
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool DelPaper(int id)
        {
            //删除操作题考试中该试卷的所有信息
            StudentExamDAL.DeleteExamInfoByPaper(id);

            string strSql = string.Format("delete from  T_Paper  where paper_id = @paper_id");
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@paper_id", id));
            if (n != 0)
            {
                // 删除对应表
                DelPaperDetailData(id);
                return true;
            }
            return false;
        }


        private static void DelPaperDetailData(int paperId)
        {
            // 删除对应理论试卷表
            string sqlCheckTheory = string.Format("if object_id('{0}') is not null select 1 else select 0", "T_PaperTheory_" + paperId);
            if ((int)SqlHelper.ExecuteScalar(sqlCheckTheory) == 1)
            {
                string sqlCreate = @"drop TABLE T_PaperTheory_" + paperId;
                SqlHelper.ExecuteNonQuery(sqlCreate);
                return;
            }

            // 删除对应操作试卷表
            string sqlCheckOperate = string.Format("if object_id('{0}') is not null select 1 else select 0", "T_PaperOperate_" + paperId);
            if ((int)SqlHelper.ExecuteScalar(sqlCheckOperate) == 1)
            {
                string sqlCreate = @"drop TABLE T_PaperOperate_" + paperId;
                SqlHelper.ExecuteNonQuery(sqlCreate);
            }
        }


        #region 理论试卷题目操作

        public static List<TheoryPaperData> GetTheoryPaperDatas()
        {
            List<Paper> papers = GetTheoryPapers(CombType.Fixed);
            List<TheoryPaperData> datas = new List<TheoryPaperData>();
            if (papers == null || papers.Count == 0)
                return null;
            foreach (var item in papers)
            {
                string sql = "select *  from T_PaperTheory_" + item.Id.ToString();
                DataTable dt = SqlHelper.ExecuteDataTable(sql);
                if (dt == null || dt.Rows.Count == 0)
                    continue;
                TheoryPaperData paperData = new TheoryPaperData();
                List<DP<int, int>> subjectDatas = new List<DP<int, int>>();

                foreach (DataRow row in dt.Rows)
                {
                    int subId = int.Parse(row["subject_id"].ToString());
                    int subScore = int.Parse(row["subject_score"].ToString());
                    subjectDatas.Add(new DP<int, int>(subId, subScore));
                }
                paperData.PaperId = item.Id;
                paperData.SubjectData = subjectDatas;
                datas.Add(paperData);
            }

            return datas;
        }

        public static List<RandomTheoryPaperData> GetRandomTheoryPaperDatas()
        {
            List<Paper> papers = GetTheoryPapers(CombType.Random);
            List<RandomTheoryPaperData> datas = new List<RandomTheoryPaperData>();
            if (papers == null || papers.Count == 0)
                return null;
            foreach (var item in papers)
            {
                string sql = "select *  from T_PaperTheory_" + item.Id.ToString();
                DataTable dt = SqlHelper.ExecuteDataTable(sql);
                if (dt == null || dt.Rows.Count == 0)
                    continue;

                RandomTheoryPaperData paperData = new RandomTheoryPaperData();

                int single_count = int.Parse(dt.Rows[0]["single_count"].ToString());
                int single_score = int.Parse(dt.Rows[0]["single_score"].ToString());
                int mult_count = int.Parse(dt.Rows[0]["mult_count"].ToString());
                int mult_score = int.Parse(dt.Rows[0]["mult_score"].ToString());
                int tf_count = int.Parse(dt.Rows[0]["tf_count"].ToString());
                int tf_score = int.Parse(dt.Rows[0]["tf_score"].ToString());
                int tbid = int.Parse(dt.Rows[0]["tbId"].ToString());

                paperData.PaperId = item.Id;
                paperData.SingleChoiceData = new DP<int, int>(single_count, single_score);
                paperData.MultChoiceData = new DP<int, int>(mult_count, mult_score);
                paperData.TFData = new DP<int, int>(tf_count, tf_score);
                paperData.TbId = tbid;

                datas.Add(paperData);
            }
            return datas;
        }
        /// <summary>
        /// 获取操作固定卷中的任务列表信息
        /// </summary>
        /// <returns></returns>
        public static List<OperatePaperData> GetOperatePaperDatas()
        {
            List<Paper> papers = GetOperatePapers(CombType.Fixed);
            List<OperatePaperData> datas = new List<OperatePaperData>();
            if (papers == null || papers.Count == 0)
                return null;
            foreach (var item in papers)
            {
                string sql = "select *  from T_PaperOperate_" + item.Id.ToString();
                DataTable dt = SqlHelper.ExecuteDataTable(sql);
                if (dt == null || dt.Rows.Count == 0)
                    continue;
                OperatePaperData paperData = new OperatePaperData();
                List<DP<int, string>> taskDatas = new List<DP<int, string>>();

                foreach (DataRow row in dt.Rows)
                {
                    int taskId = Int32.Parse(row["task_id"].ToString());
                    //int postId = Int32.Parse(row["post_id"].ToString());
                    string steps = row["score"].Equals(DBNull.Value) ? "" : row["score"].ToString();

                    taskDatas.Add(new DP<int, string>(taskId/*, postId*/, steps));
                }
                paperData.PaperId = item.Id;
                paperData.TaskData = taskDatas;
                datas.Add(paperData);
            }

            return datas;
        }

        public static List<RandomOperatePaperData> GetRandomOperatePaperDatas()
        {
            List<Paper> papers = GetOperatePapers(CombType.Random);
            List<RandomOperatePaperData> datas = new List<RandomOperatePaperData>();
            if (papers == null || papers.Count == 0)
                return null;
            foreach (var item in papers)
            {
                string sql = "select *  from T_PaperOperate_" + item.Id.ToString();
                DataTable dt = SqlHelper.ExecuteDataTable(sql);
                if (dt == null || dt.Rows.Count == 0)
                    continue;

                RandomOperatePaperData paperData = new RandomOperatePaperData();

                int taskcount = Int32.Parse(dt.Rows[0]["task_count"].ToString());
                //int postId = Int32.Parse(row["post_id"].ToString());
                int score = Int32.Parse(dt.Rows[0]["score"].ToString());

                paperData.PaperId = item.Id;
                paperData.TaskData = new DP<int, int>(taskcount, score);

                datas.Add(paperData);
            }
            return datas;
        }


        private static Dictionary<int, int> ReadTheoryPaperData(DataRow dr)
        {

            int subId = Int32.Parse(dr["subject_id"].ToString());
            int subScore = Int32.Parse(dr["subject_score"].ToString());
            Dictionary<int, int> pairs = new Dictionary<int, int>();
            pairs.Add(subId, subScore);
            return pairs;
        }

        public static List<Subject> GetSubjectInPaper(int paperid)
        {

            string strSql = "select * from T_PaperTheory_" + paperid;
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null) { return null; }

            List<Subject> list = new List<Subject>();

            foreach (DataRow dr in dt.Rows)
            {
                Subject sub = ReadSubjectInPaper(paperid, dr);
                if (sub != null)
                    list.Add(sub);
            }
            return list;

        }

        private static Subject ReadSubjectInPaper(int paperId, DataRow dr)
        {
            Subject sub = new Subject();
            int id = Int32.Parse(dr["subject_id"].ToString());
            sub = SubjectDAL.GetSubjectById(id);

            if (sub != null)
                sub.Score = Int32.Parse(dr["subject_score"].ToString());
            else
                DelSubjectInPaper(paperId, id);//删除不存在的试题
            return sub;
        }

        public static bool DelSubjectInPaper(int paperId, int subId)
        {
            string strSql = string.Format("delete from  T_PaperTheory_" + paperId + "  where subject_id = @id ");
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@id", subId));
            if (n != 0)
            {
                return true;
            }
            return false;
        }

        public static void ClearSubjectsInPaper(int paperid)
        {
            //清空已有数据，并且将自增自段恢复从1开始计数 
            string sql = "truncate table T_PaperTheory_" + paperid;
            SqlHelper.ExecuteNonQuery(sql);
        }

        public static List<int> GetSujectIds(int paperid)
        {
            string strSql = "select subject_id from T_PaperTheory_" + paperid;
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null) { return null; }

            List<int> list = new List<int>();

            foreach (DataRow dr in dt.Rows)
            {
                int id = Int32.Parse(dr["subject_id"].ToString());
                list.Add(id);
            }
            return list;
        }

        /// <summary>
        /// 管理固定理论试卷中的试题
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="subjectId"></param>
        /// <param name="score"></param>
        public static void ManageSubjectInPaper(int paperId, int subjectId, int score = 0)
        {
            string strSql = string.Format(@"insert into T_PaperTheory_" + paperId + " (subject_id,subject_score)values({0},{1})", subjectId, score);
            SqlHelper.ExecuteScalar(strSql);
        }
        /// <summary>
        /// 管理随机理论试卷中的试题数量分值
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="subjectId"></param>
        public static void ManageSubjectInRandomPaper(RandomTheoryPaperData data)
        {

            string strSql = string.Format(@"insert T_PaperTheory_" + data.PaperId + " (single_count,single_score,mult_count,mult_score,tf_count ,tf_score,tbId)values({0},{1},{2},{3},{4},{5},{6})",
                data.SingleChoiceData.Value1, data.SingleChoiceData.Value2, data.MultChoiceData.Value1, data.MultChoiceData.Value2, data.TFData.Value1, data.TFData.Value2,data.TbId);

            SqlHelper.ExecuteScalar(strSql);
        }

        /// <summary>
        /// 修改理论卷中试题的分值
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="subId"></param>
        /// <param name="score"></param>
        /// <returns></returns>
        public static bool ModifySubjectScore(int paperId, int subId, int score)
        {
            string strSql = string.Format("update T_PaperTheory_" + paperId + " set subject_score={0} where subject_id = @id ", score);
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@id", subId));
            if (n != 0)
            {
                return true;
            }
            return false;
        }
        #endregion

        #region 操作试卷中任务处理
        public static List<TaskModel> GetTasksInPaper(int examid, int paperid, int userId)
        {
            Paper paper = GetPaperByID(paperid);
            List<TaskModel> list = new List<TaskModel>();
            string strSql = "select * from T_PaperOperate_" + paperid;
            DataTable dt = SqlHelper.ExecuteDataTable(strSql);
            if (dt == null) { return null; }
            if (paper.CombType == CombType.Fixed)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    TaskModel task = ReadTaskInFixedPaper(paper.ProjectId, dr);
                    if (task != null)
                        list.Add(task);
                }
            }
            else if (paper.CombType == CombType.Random)
            {
                // List<TaskModel> listTask = null;
                if (CheckIsExamed(examid, userId, paper.ProjectId, out list))
                    return list;
                else
                {
                    int taskCount = int.Parse(dt.Rows[0]["task_count"].ToString());
                    list = TaskDAL.GetRandomTasks(paper.ProjectId, taskCount);
                }
            }
            return list;
        }
        /// <summary>
        /// 判断随机卷是否已经考试，若已考试，则在考试记录表中获取任务列表
        /// </summary>
        /// <param name="examid"></param>
        /// <param name="userId"></param>
        /// <param name="projectId"></param>
        /// <param name="listTask"></param>
        /// <returns></returns>
        private static bool CheckIsExamed(int examid, int userId, int projectId, out List<TaskModel> listTask)
        {
            listTask = null;

            string sql = string.Format("select count,exam_log from T_StudentExamData where studentID = {0} and exam_id = {1}", userId, examid);
            DataTable dt = SqlHelper.ExecuteDataTable(sql);
            if (dt == null)
            {
                return false;
            }

            int count = dt.Rows[0][0].Equals(DBNull.Value) ? 0 : int.Parse(dt.Rows[0][0].ToString());
            if (count == 0)
            {
                return false;
            }
            else
            {
                string examlog = dt.Rows[0][1].Equals(DBNull.Value) ? "" : dt.Rows[0][1].ToString();
                List<ExamLog> list = LitJson.JsonMapper.ToObject<List<ExamLog>>(examlog);
                if (list != null && list.Count != 0)
                {
                    listTask = new List<TaskModel>();
                    foreach (var item in list)
                    {
                        TaskModel task = TaskDAL.GetTaskById(projectId, item.SubjectId);
                        listTask.Add(task);
                    }
                }
            }
            return true;


        }

        private static TaskModel ReadTaskInFixedPaper(int projectId, DataRow dr)
        {
            TaskModel task = new TaskModel();
            int taskId = int.Parse(dr["task_id"].ToString());
            int postid = dr["post_id"].Equals(DBNull.Value) ? 0 : int.Parse(dr["post_id"].ToString());
            string stepScore = dr["score"].Equals(DBNull.Value) ? "" : dr["score"].ToString();

            task = TaskDAL.GetTaskById(projectId, taskId);

            if (task != null)
            {
                task.StepScore = dr["score"].Equals(DBNull.Value) ? "" : dr["score"].ToString();
                task.ExamPostId = postid;
            }
            return task;
        }


        #endregion

        public static bool ModifyPaperTime(int id, int time)
        {
            string strSql = string.Format("update T_PaperOperates set time='{0}' where id = @id", time);
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@id", id));
            if (n != 0)
            {

                return true;
            }
            return false;
        }

        public static void ClearTasksInPaper(int paperid)
        {
            //清空已有数据，并且将自增自段恢复从1开始计数 
            string sql = "truncate table T_PaperOperate_" + paperid;
            SqlHelper.ExecuteNonQuery(sql);
        }
        /// <summary>
        /// 管理固定操作试卷中的任务
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="taskId"></param>
        public static void ManageTaskInPaper(int paperId, int taskId, string steps/*, int postId = 0*/)
        {
            string strSql = string.Format(@"insert into T_PaperOperate_" + paperId + " (task_id,score)values({0},'{1}')", taskId, steps);
            SqlHelper.ExecuteScalar(strSql);
        }

        /// <summary>
        /// 管理固定操作试卷中的任务
        /// </summary>
        /// <param name="paperId"></param>
        /// <param name="taskId"></param>
        public static void ManageTaskInRandomPaper(RandomOperatePaperData data)
        {
            string strSql = string.Format(@"insert into T_PaperOperate_" + data.PaperId + " (task_count,score)values({0},{1})", data.TaskData.Value1, data.TaskData.Value2);
            SqlHelper.ExecuteScalar(strSql);
        }


        /// <summary>
        /// 修改试卷中的考试岗位
        /// </summary>
        /// <param name="id"></param>
        /// <param name="post"></param>
        /// <returns></returns>
        public static bool ModifyExamPostInPaper(int paperId, int taskId, int post)
        {
            string strSql = string.Format("update T_PaperOperate_" + paperId + " set post_id={0} where task_id = @id", post);
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@id", taskId));
            if (n != 0)
            {
                return true;
            }
            return false;
        }
        public static bool ModifyExamScore(int paperId, int taskId, int score)
        {
            string strSql = string.Format("update T_PaperOperate_" + paperId + " set score={0} where task_id = @id", score);
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@id", taskId));
            if (n != 0)
            {
                return true;
            }
            return false;
        }

        public static bool DelTaskInPaper(int paperId, int taskId)
        {
            string strSql = string.Format("delete from  T_PaperOperate_" + paperId + "  where task_id = @id");
            int n = SqlHelper.ExecuteNonQuery(strSql, new SqlParameter("@id", taskId));
            if (n != 0)
            {
                return true;
            }
            return false;
        }

    }
}
